home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / toolpa.zip / TUTOR.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-22  |  15KB  |  443 lines

  1. {*-----------------------------------------------------------------
  2.  * tutor.pas - My First PowerCode App                                                     
  3.  * 4/22/92 - 6:28:35pm                                                                     
  4.  * John Doe                                                                                 
  5.  *-----------------------------------------------------------------}
  6.  
  7. program Tutor;
  8.  
  9. uses WinTypes, WinProcs, WObjects, Jtools;
  10.  
  11. const
  12.     cm_MainApp =    500;
  13.     cm_MainDialog = 501;
  14.     cm_MainWindow = 502;
  15.     cm_MainCheckBox = 503;
  16.     cm_New =       1000;
  17.     cm_Open =      1001;
  18.     cm_Save =      1002;
  19.     cm_Exit =      1003;
  20.     cm_About =     1004;
  21.     ID_LNAME =      100;
  22.     ID_NAME =       101;
  23.     ID_TITLE =      102;
  24.     ID_CONAME =     103;
  25.     ID_STREET1 =    104;
  26.     ID_STREET2 =    105;
  27.     ID_CITY =       106;
  28.     ID_STATE =      107;
  29.     ID_ZIP =        108;
  30.     ID_BPHONE =     109;
  31.     ID_HPHONE =     110;
  32.     ID_FAX =        111;
  33.     ID_COMMENTS =   112;
  34.     ID_SEARCH =     113;
  35.     ID_ADDTYPE =    114;
  36.     ID_MALE =       115;
  37.     ID_FEMALE =     116;
  38.     ID_LIST =       117;
  39.  
  40.  
  41. type
  42.   PMain = ^TMain;
  43.   TMain = object(TWindow)
  44.     constructor Init(AParent: PWindowsObject);
  45.     procedure SetupWindow; virtual;
  46.     procedure GetWindowClass(var AWndClass: TWndClass);virtual;
  47.     function GetClassName: PChar;virtual;
  48.     procedure MsgMainApp(var Msg: TMessage);
  49.       virtual cm_First + cm_MainApp;
  50.     procedure MsgMainDialog(var Msg: TMessage);
  51.       virtual cm_First + cm_MainDialog;
  52.     procedure MsgMainWindow(var Msg: TMessage);
  53.       virtual cm_First + cm_MainWindow;
  54.     procedure MsgNew(var Msg: TMessage);
  55.       virtual cm_First + cm_New;
  56.     procedure MsgOpen(var Msg: TMessage);
  57.       virtual cm_First + cm_Open;
  58.     procedure MsgSave(var Msg: TMessage);
  59.       virtual cm_First + cm_Save;
  60.     procedure MsgExit(var Msg: TMessage);
  61.       virtual cm_First + cm_Exit;
  62.     procedure MsgAbout(var Msg: TMessage);
  63.       virtual cm_First + cm_About;
  64.   end;
  65. type
  66.   PNewWin = ^TNewWin;
  67.   TNewWin = object(TWindow)
  68.     constructor Init(AParent: PWindowsObject);
  69.     procedure SetupWindow; virtual;
  70.     procedure GetWindowClass(var AWndClass: TWndClass);virtual;
  71.     function GetClassName: PChar;virtual;
  72.   end;
  73. type
  74.   PAbout = ^TAbout;
  75.   TAbout = object(TDialog)
  76.   WorkStr : array[0..80] of Char;
  77.  
  78.     constructor Init(AParent: PWindowsObject; AName : PChar);
  79.     procedure SetupWindow; virtual;
  80.     function CanClose: Boolean;virtual;
  81.     procedure Cancel(var Msg: TMessage);
  82.       virtual id_First + id_Cancel;
  83.   end;
  84. type
  85.   PAddress = ^TAddress;
  86.   TAddress = object(TDialog)
  87.   WorkStr : array[0..80] of Char;
  88.     EdLname, EdName, EdTitle, EdConame, EdStreet1, EdStreet2, EdCity, EdState,
  89. EdZip, EdBphone, EdHphone, EdFax, EdComments : PEdit;
  90.     RbMale, RbFemale : PRadioButton;
  91.     CoAddtype : PComboBox;
  92.  
  93.     constructor Init(AParent: PWindowsObject; AName : PChar);
  94.     procedure SetupWindow; virtual;
  95.     function CanClose: Boolean;virtual;
  96.     procedure Cancel(var Msg: TMessage);
  97.       virtual id_First + id_Cancel;
  98.     procedure MsgSearch(var Msg: TMessage);
  99.       virtual id_First + ID_SEARCH;
  100.   end;
  101. type
  102.   PSearch = ^TSearch;
  103.   TSearch = object(TDialog)
  104.   WorkStr : array[0..80] of Char;
  105.     LbList : PListBox; 
  106.  
  107.     constructor Init(AParent: PWindowsObject; AName : PChar);
  108.     procedure SetupWindow; virtual;
  109.     function CanClose: Boolean;virtual;
  110.     procedure Cancel(var Msg: TMessage);
  111.       virtual id_First + id_Cancel;
  112.   end;
  113.  
  114. type
  115.     TTutorApp = object(TApplication)
  116.       procedure InitMainWindow; virtual;
  117.     end;
  118.  
  119. {*-----------------------------------------------------------------
  120.  * Window Method implementations - Main    
  121.  *-----------------------------------------------------------------}
  122. constructor TMain.Init(AParent: PWindowsObject);
  123. var pTB : PToolBar;
  124. begin
  125.   TWindow.Init(AParent, 'My First PowerCode App');
  126.   Attr.Menu := LoadMenu(HInstance, 'Main');
  127.     { Create ToolBar - This is a child window so OWL will delete }
  128.     pTB := New(PToolBar, Init(@Self, 44));    
  129.     pTB^.AddToolItem(@Self, 'Button', CM_MAINAPP, -1, -1, 45, 45, 
  130.         'NMainApp', 'SMainApp', 'Y', 'Y');
  131.     pTB^.AddToolItem(@Self, 'Button', CM_MAINDIALOG, 43, -1, 45, 45, 
  132.         'NMainDialog', 'SMainDialog', 'Y', 'Y');
  133.     pTB^.AddToolItem(@Self, 'Button', CM_MAINWINDOW, 87, -1, 45, 45, 
  134.         'NMainWindow', 'SMainWindow', 'Y', 'Y');
  135.     pTB^.AddToolItem(@Self, 'Checkbox', CM_MAINCHECKBOX, 134, 2, 40, 40, 
  136.         'NMainCheckBox', 'SMainCheckBox', 'N', 'N');
  137. end;
  138.  
  139. {*-----------------------------------------------------------------
  140.  * procedure TMain.GetWindowClass
  141.  * Allows window class info to be modified (icon, color, etc.)
  142.  *-----------------------------------------------------------------}
  143. procedure TMain.GetWindowClass(var AWndClass: TWndClass);
  144. begin
  145.   TWindow.GetWindowClass(AWndClass); { Get the default class }
  146.     AWndClass.hbrBackground := CreateSolidBrush(RGB(255,255,128));
  147.   AWndClass.hIcon := LoadIcon(HInstance, 'Main');
  148. end;
  149.  
  150. {*-----------------------------------------------------------------
  151.  * function TMain.GetClassName
  152.  * Returns a unique class name for the window class.
  153.  *-----------------------------------------------------------------}
  154. function TMain.GetClassName: PChar;
  155. begin
  156.   GetClassName := 'Main';
  157. end;
  158.  
  159. {*-----------------------------------------------------------------
  160.  * procedure TMain.SetupWindow
  161.  * Setup all child windows and controls.
  162.  * Perform any window setup operations requiring a window handle.
  163.  *-----------------------------------------------------------------}
  164. procedure TMain.SetupWindow;
  165. begin
  166.   TWindow.SetupWindow;
  167. end;
  168.  
  169. {*-----------------------------------------------------------------
  170.  * Window Response Methods  - Main            
  171.  *-----------------------------------------------------------------}
  172. procedure TMain.MsgMainApp(var Msg: TMessage);
  173. begin
  174.     WinExec('notepad.exe tutor.txt', SW_SHOW);
  175.  
  176. end;
  177. procedure TMain.MsgMainDialog(var Msg: TMessage);
  178. var pDlg : PDialog;
  179. begin
  180.     pDlg := New(PADDRESS, Init(@Self, 'ADDRESS'));
  181.     Application^.MakeWindow(pDlg);
  182.     pDlg^.Show(SW_SHOW);
  183.  
  184. end;
  185. procedure TMain.MsgMainWindow(var Msg: TMessage);
  186. var pWin : PWindow;
  187. begin
  188.     pWin := New(PNewWin, Init(@Self));
  189.     Application^.MakeWindow(pWin);
  190.     pWin^.Show(SW_SHOW);
  191.  
  192. end;
  193. procedure TMain.MsgNew(var Msg: TMessage);
  194. var pWin : PWindow;
  195. begin
  196.     pWin := New(PNewWin, Init(@Self));
  197.     Application^.MakeWindow(pWin);
  198.     pWin^.Show(SW_SHOW);
  199.  
  200. end;
  201. procedure TMain.MsgOpen(var Msg: TMessage);
  202. begin
  203.     MessageBox(HWindow, 'User Clicked on Item : &Open', 'Info', 
  204.        mb_Ok or mb_IconInformation);
  205.  
  206. end;
  207. procedure TMain.MsgSave(var Msg: TMessage);
  208. begin
  209.     MessageBox(HWindow, 'User Clicked on Item : &Save', 'Info', 
  210.        mb_Ok or mb_IconInformation);
  211.  
  212. end;
  213. procedure TMain.MsgExit(var Msg: TMessage);
  214. begin
  215.     MessageBox(HWindow, 'User Clicked on Item : &Exit', 'Info', 
  216.        mb_Ok or mb_IconInformation);
  217.  
  218. end;
  219. procedure TMain.MsgAbout(var Msg: TMessage);
  220. var pDlg : PDialog;
  221. begin
  222.     Application^.ExecDialog(New(PAbout, Init(@Self, 'ABOUT'))); 
  223.  
  224. end;
  225. {*-----------------------------------------------------------------
  226.  * Window Method implementations - NewWin    
  227.  *-----------------------------------------------------------------}
  228. constructor TNewWin.Init(AParent: PWindowsObject);
  229. begin
  230.   TWindow.Init(AParent, '');
  231.   Attr.Menu := LoadMenu(HInstance, '');
  232.     Attr.Style := WS_OVERLAPPEDWINDOW or ws_Visible;
  233. end;
  234.  
  235. {*-----------------------------------------------------------------
  236.  * procedure TNewWin.GetWindowClass
  237.  * Allows window class info to be modified (icon, color, etc.)
  238.  *-----------------------------------------------------------------}
  239. procedure TNewWin.GetWindowClass(var AWndClass: TWndClass);
  240. begin
  241.   TWindow.GetWindowClass(AWndClass); { Get the default class }
  242. end;
  243.  
  244. {*-----------------------------------------------------------------
  245.  * function TNewWin.GetClassName
  246.  * Returns a unique class name for the window class.
  247.  *-----------------------------------------------------------------}
  248. function TNewWin.GetClassName: PChar;
  249. begin
  250.   GetClassName := 'NewWin';
  251. end;
  252.  
  253. {*-----------------------------------------------------------------
  254.  * procedure TNewWin.SetupWindow
  255.  * Setup all child windows and controls.
  256.  * Perform any window setup operations requiring a window handle.
  257.  *-----------------------------------------------------------------}
  258. procedure TNewWin.SetupWindow;
  259. begin
  260.   TWindow.SetupWindow;
  261. end;
  262.  
  263. {*-----------------------------------------------------------------
  264.  * Window Response Methods  - NewWin            
  265.  *-----------------------------------------------------------------}
  266. {*-----------------------------------------------------------------
  267.  * Dialog Method implementations - TAbout    
  268.  *-----------------------------------------------------------------}
  269. constructor TAbout.Init(AParent: PWindowsObject; AName :PChar);
  270. begin
  271.   TDialog.Init(AParent, AName);
  272. end;
  273.  
  274.  
  275. {*-----------------------------------------------------------------
  276.  * procedure TAbout.SetupWindow
  277.  * Setup all child windows and controls.
  278.  * Perform any window setup operations requiring a window handle.
  279.  *-----------------------------------------------------------------}
  280. procedure TAbout.SetupWindow;
  281. begin
  282.   TDialog.SetupWindow;
  283. end;
  284.  
  285. {*-----------------------------------------------------------------
  286.  * function TAbout.CanClose
  287.  * Determine if dialog should be allowed to update
  288.  *-----------------------------------------------------------------}
  289. function TAbout.CanClose : Boolean;
  290. var I : Word;
  291. begin
  292.         CanClose := true;
  293. end;
  294. {*-----------------------------------------------------------------
  295.  * procedure TAbout.Cancel
  296.  * Overide Cancel method because TDialog incorrectly calls 
  297.  * CanClose on a Cancel
  298.  *-----------------------------------------------------------------}
  299. procedure TAbout.Cancel(var Msg: TMessage);
  300. begin
  301.     EndDlg(idcancel);
  302. end;
  303. {*-----------------------------------------------------------------
  304.  * Dialog Response Methods  - TAbout
  305.  *-----------------------------------------------------------------}
  306. {*-----------------------------------------------------------------
  307.  * Dialog Method implementations - TAddress    
  308.  *-----------------------------------------------------------------}
  309. constructor TAddress.Init(AParent: PWindowsObject; AName :PChar);
  310. begin
  311.   TDialog.Init(AParent, AName);
  312.     New(EdLname, InitResource(@Self, ID_LNAME, 30));
  313.     New(EdName, InitResource(@Self, ID_NAME, 0));
  314.     New(EdTitle, InitResource(@Self, ID_TITLE, 0));
  315.     New(EdConame, InitResource(@Self, ID_CONAME, 0));
  316.     New(EdStreet1, InitResource(@Self, ID_STREET1, 0));
  317.     New(EdStreet2, InitResource(@Self, ID_STREET2, 0));
  318.     New(EdCity, InitResource(@Self, ID_CITY, 0));
  319.     New(EdState, InitResource(@Self, ID_STATE, 0));
  320.     New(EdZip, InitResource(@Self, ID_ZIP, 0));
  321.     New(EdBphone, InitResource(@Self, ID_BPHONE, 0));
  322.     New(EdHphone, InitResource(@Self, ID_HPHONE, 0));
  323.     New(EdFax, InitResource(@Self, ID_FAX, 0));
  324.     New(EdComments, InitResource(@Self, ID_COMMENTS, 0));
  325.     New(CoAddtype, InitResource(@Self, ID_ADDTYPE, 0));
  326.     New(RbMale, InitResource(@Self, ID_MALE));
  327.     New(RbFemale, InitResource(@Self, ID_FEMALE));
  328. end;
  329.  
  330.  
  331. {*-----------------------------------------------------------------
  332.  * procedure TAddress.SetupWindow
  333.  * Setup all child windows and controls.
  334.  * Perform any window setup operations requiring a window handle.
  335.  *-----------------------------------------------------------------}
  336. procedure TAddress.SetupWindow;
  337. begin
  338.   TDialog.SetupWindow;
  339.     RbFemale^.Check;     { Set Initial Check }
  340.     { Fill Combo with initial values }
  341.     CoAddtype^.AddString('Employee');
  342.     CoAddtype^.AddString('Vendor');
  343.     CoAddtype^.AddString('Friend');
  344.     CoAddtype^.AddString('Other');
  345. end;
  346.  
  347. {*-----------------------------------------------------------------
  348.  * function TAddress.CanClose
  349.  * Determine if dialog should be allowed to update
  350.  *-----------------------------------------------------------------}
  351. function TAddress.CanClose : Boolean;
  352. var I : Word;
  353. begin
  354.     if EdLname^.GetText(WorkStr, 80) = 0 then
  355.     begin
  356.         MessageBox(HWindow, 'Mandatory field requires input.', 'Error', 
  357.            MB_OK or MB_ICONEXCLAMATION);
  358.         SetFocus(EdLname^.HWindow);     { Position cursor to error }
  359.         CanClose := false;
  360.         exit;
  361.     end;
  362.         CanClose := true;
  363. end;
  364. {*-----------------------------------------------------------------
  365.  * procedure TAddress.Cancel
  366.  * Overide Cancel method because TDialog incorrectly calls 
  367.  * CanClose on a Cancel
  368.  *-----------------------------------------------------------------}
  369. procedure TAddress.Cancel(var Msg: TMessage);
  370. begin
  371.     Done;     { Delete modeless dialog box }
  372. end;
  373. {*-----------------------------------------------------------------
  374.  * Dialog Response Methods  - TAddress
  375.  *-----------------------------------------------------------------}
  376. procedure TAddress.MsgSearch(var Msg: TMessage);
  377. var pDlg : PDialog;
  378. begin
  379.     Application^.ExecDialog(New(PSearch, Init(@Self, 'SEARCH'))); 
  380.  
  381. end;
  382. {*-----------------------------------------------------------------
  383.  * Dialog Method implementations - TSearch    
  384.  *-----------------------------------------------------------------}
  385. constructor TSearch.Init(AParent: PWindowsObject; AName :PChar);
  386. begin
  387.   TDialog.Init(AParent, AName);
  388.     New(LbList, InitResource(@Self, ID_LIST));
  389. end;
  390.  
  391.  
  392. {*-----------------------------------------------------------------
  393.  * procedure TSearch.SetupWindow
  394.  * Setup all child windows and controls.
  395.  * Perform any window setup operations requiring a window handle.
  396.  *-----------------------------------------------------------------}
  397. procedure TSearch.SetupWindow;
  398. begin
  399.   TDialog.SetupWindow;
  400. end;
  401.  
  402. {*-----------------------------------------------------------------
  403.  * function TSearch.CanClose
  404.  * Determine if dialog should be allowed to update
  405.  *-----------------------------------------------------------------}
  406. function TSearch.CanClose : Boolean;
  407. var I : Word;
  408. begin
  409.         CanClose := true;
  410. end;
  411. {*-----------------------------------------------------------------
  412.  * procedure TSearch.Cancel
  413.  * Overide Cancel method because TDialog incorrectly calls 
  414.  * CanClose on a Cancel
  415.  *-----------------------------------------------------------------}
  416. procedure TSearch.Cancel(var Msg: TMessage);
  417. begin
  418.     EndDlg(idcancel);
  419. end;
  420. {*-----------------------------------------------------------------
  421.  * Dialog Response Methods  - TSearch
  422.  *-----------------------------------------------------------------}
  423. {*-----------------------------------------------------------------
  424.  * TTutorApp method implementations:        
  425.  *-----------------------------------------------------------------}
  426.  
  427. procedure TTutorApp.InitMainWindow;
  428. begin
  429.   MainWindow := New(PMain, Init(nil));
  430. end;
  431.  
  432. {*-----------------------------------------------------------------
  433.  * Main Program:
  434.  *-----------------------------------------------------------------}
  435. var
  436.   TutorApp: TTutorApp;
  437.  
  438. begin
  439.   TutorApp.Init('Tutor');
  440.   TutorApp.Run;
  441.   TutorApp.Done;
  442. end.
  443.